package cn.woochen.mvvmframe.activity

import androidx.recyclerview.widget.LinearLayoutManager
import cn.woochen.comlib.adapter.RecycleViewDivider
import cn.woochen.comlib.util.ext.dp
import cn.woochen.mvvmframe.R
import cn.woochen.mvvmframe.adapter.ExampleAdapter
import cn.woochen.mvvmframe.bean.VersionBean
import cn.woochen.mvvmframe.config.BaseActivity
import cn.woochen.mvvmframe.databinding.ActivityMainBinding
import cn.woochen.mvvmframe.helper.ApkUpdateHelper
import cn.woochen.mvvmframe.viewmodels.EmptyViewModel

class MainActivity : BaseActivity<ActivityMainBinding, EmptyViewModel>() {

    private val mExampleDatas by lazy {
        mutableListOf("网络请求","WebView","拍照","版本升级","富文本","消息通知","测试")
    }

    private val mExampleAdapter by lazy {
        ExampleAdapter(mExampleDatas)
    }

    override fun setContentView(): Int = R.layout.activity_main

    override fun initData() {
        setStatusBarStyle(false)
        initWidgets()
    }

    /**
     * 组件初始化
     */
    private fun initWidgets() {
        mBinding.rvItem.adapter = mExampleAdapter
        mBinding.rvItem.addItemDecoration(RecycleViewDivider(mContext,LinearLayoutManager.VERTICAL, 10f.dp.toInt(),false))
        mExampleAdapter.setOnItemClickListener { _, _, position ->
            when (position) {
                0 -> { //网络请求
                    NetActivity.start(mContext)
                }
                1 -> { //webview测试
                    WebViewActivity.start(mContext)
                }
                2 -> { //拍照
                    PhotoActivity.start(mContext)
                }
                3 -> { //版本升级
                    ApkUpdateHelper().update(this, VersionBean())
                }
                4 -> { //富文本
                    SpanTextActivity.start(mContext)
                }
                5 -> { //消息通知
                    NotificationActivity.start(mContext)
                }
                else -> { //测试
                    TestActivity.start(mContext)
                }
            }
        }

    }
}